package Client;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import org.omg.CORBA.ORB;

/*
 * la classe client pour faire invoquation dynamique
 */
public class ClientInvoque
{
    public static void main( String[] args )
    {

        /*
         * initiation les ORB
         */
        ORB orb = ORB.init(args, null);

  

        ////////////////////////////////////////////////////
        String ior = null;

        try {
            String ref = "invo.ref";
            FileInputStream file = new FileInputStream(ref);
            BufferedReader in = new BufferedReader(new InputStreamReader(file));
            ior = in.readLine();
            file.close();
        } catch (IOException ex) {
            System.err.println("Impossible de lire fichier : `" +
                ex.getMessage() + "'");
            System.exit(1);
        }

       org.omg.CORBA.Object s = orb.string_to_object(ior);

        if (s == null) {
            System.err.println("Erreur sur string_to_object() ");
            throw new RuntimeException();
        }


        try {
		
		org.omg.CORBA.Request request = s._request("Recherche");
	    
		request.set_return_type( 
                    orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_objref));

		request.invoke();

		if(request.env().exception() != null)
                {
		    throw request.env().exception();
                }
		else
                {
		    		System.out.println("l'operation est reussir");  
                }
	  }
	  catch (Exception e)
	    {
		e.getStackTrace();
		e.getMessage();
	    }
  }

		
}
